var HttpService = function() {

	return {
		getServiceUrl : function(para) {

			var url = this.getRootPath();

			if (para != null) {

				var callpara = para.callPara;
				var urlPara = {};
				for (var p in callpara) {
					var urlp = encodeURI(p);
					var urlv = encodeURI(callpara[p]);
					urlPara[urlp] = urlv;
				}

				url = url + 'main?cName=' + para.className + '&cMethod='
						+ para.callMethod
						
				if (para.callPara != null) {
					url = url + '&para=' + Ext.encode(urlPara);
				}
				
			} else {
				url = url + 'main';
			}

			return url;
		},
		
		call: function(para) {
			var params = {}
			if (para.requestPara != null) {
				params = para.requestPara
			}
			//params.cName = para.servlet;
			//params.cMethod = para.callMethod;
//			alert(Ext.encode(para.callPara));
			params.para = para.callPara == null ? null : Ext.encode(para.callPara);
//            alert(params.para);
			var url = this.getRootPath();
//			alert(url);

			var config = {
				url : url + para.servlet,// http://localhost:8080/iSearch/
				method : 'post',
				params : params,
				// scope: scope,
				success : function(response, options) {
					var responseArray = Ext.decode(response.responseText);
							
					var scope = para.scope;
					if(!scope){
						scope = this;
					}
					para.callBackMethod.call(scope,responseArray, para.callBackPara);
				}

			};
			Ext.Ajax.request(config);
		},

		getServiceUrlNoUrlEncode : function(para) {

			var url = this.getRootPath();
			if (para != null) {
				url = url + 'main?cName=' + para.className + '&cMethod='
						+ para.callMethod
				if (para.callPara != null) {
					url = url + '&para=' + Ext.util.JSON.encode(para.callPara);
				}

			} else {
				url = url + 'main';
			}

			return url;
		},
		
		getRootPath : function() {
			var strFullPath = window.document.location.href;
			var strPath = window.document.location.pathname;
			var pos = strFullPath.indexOf(strPath);
			var prePath = strFullPath.substring(0, pos);
			var postPath = strPath.substring(0, strPath.substr(1).indexOf('/')
							+ 1);
			return (prePath + postPath + '/');
		}
	}
}();

var ajax = HttpService;
